package com.wxapp.custom.service.controller.client;

import com.wxapp.common.constant.base.IBaseController;
import com.wxapp.common.constant.pojo.vm.ResultVm;
import com.wxapp.common.constant.pojo.vo.UserVo;
import com.wxapp.common.core.annotation.User;
import com.wxapp.custom.api.pojo.vm.address.PAddressDetailVm;
import com.wxapp.custom.api.pojo.vm.address.PAddressPageVm;
import com.wxapp.custom.api.pojo.vo.address.QAddressAddVo;
import com.wxapp.custom.api.pojo.vo.address.QAddressUpdateVo;
import com.wxapp.custom.service.service.AddressService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lgl
 * @Description 地址管理
 * @Datetime 2023/10/9 14:11
 * @Modified By
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/client/address")
@Tag(name = "地址管理")
public class AddressClientController extends IBaseController {
    private final AddressService addressService;

    @PostMapping("add")
    @Operation(summary ="新建地址")
    public ResultVm<String> add(@Schema(hidden = true) @User UserVo userVo, @RequestBody @Validated QAddressAddVo qAddressAddVo) {
        return addressService.add(userVo, qAddressAddVo);
    }

    @PutMapping("update")
    @Operation(summary ="更新地址")
    public ResultVm<String> update(@RequestBody QAddressUpdateVo qAddressUpdateVo, @Schema(hidden = true) @User UserVo userVo) {
        return addressService.update(qAddressUpdateVo, userVo);
    }

    @DeleteMapping("delete/{id}")
    @Operation(summary ="删除地址")
    public ResultVm<String> delete(@PathVariable String id, @Schema(hidden = true) @User UserVo userVo) {
        return addressService.delete(id, userVo);
    }

    @GetMapping("getDetail/{id}")
    @Operation(summary ="获取地址信息")
    public ResultVm<PAddressDetailVm> getDetail(@PathVariable String id) {
        return addressService.getDetail(id);
    }

    @GetMapping("list")
    @Operation(summary ="获取地址列表")
    public ResultVm<List<PAddressPageVm>> list(@Schema(hidden = true) @User UserVo userVo) {
        return addressService.list(userVo);
    }
}
